#include <workdir.filesystem.Abstract.h>

using namespace std;
using namespace nemesis;
using namespace workdir;

filesystem::Abstract::Abstract (const Abstract::ClassType::_v classType, const std::string& name) :
   a_classType (classType),
   a_name (name), a_parent (NULL) 
{
   a_path = name;
}

filesystem::Abstract::Abstract (const Abstract::ClassType::_v classType, filesystem::Abstract* parent, const std::string& name) : 
   a_classType (classType),
   a_name (name), 
   a_parent (parent) 
{ 
   a_parent->a_children.push_back (this);
   a_path = calculePath (parent, name);
}

/*virtual*/
filesystem::Abstract::~Abstract ()
{
   for (child_iterator ii = child_begin (), maxii = child_end (); ii != maxii; ii ++)
      delete child (ii);
   
   a_children.clear ();
}

/* static */
string filesystem::Abstract::calculePath (const filesystem::Abstract* parent, const std::string& shortPath) 
   throw ()
{
   string result;
   
   if (parent!= NULL) {
      result = parent->a_path;
      result += '/';
   }
   
   return result += shortPath;
}
